package com.booksmanager.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.booksmanager.annotation.Log;
import com.booksmanager.pojo.ReturnBooks;
import com.booksmanager.service.BoorowBooksService;
import com.booksmanager.service.ReturnBooksService;
import com.booksmanager.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 * 还书表 前端控制器
 * </p>
 *
 * @author Yan
 * @since 2020-05-24
 */
@Api(value = "/returnbooks", tags = "还书表")
@RestController
@RequestMapping("/returnbooks")
public class ReturnBooksController {


    @Autowired
    private ReturnBooksService returnBooksService;
    @Autowired
    private BoorowBooksService boorowBooksService;

    /**
     * 分页查询图书列表
     * @param page
     * @param returnBooks
     * @return
     */
    @ApiOperation(value = "分页查询图书列表")
    @GetMapping("/page")
    public R page(Page page, ReturnBooks returnBooks) {
        return new R(returnBooksService.queryReturnBooks(page, returnBooks));
    }

    /**
     * 新增还书记录
     * @param returnBooks
     * @return
     */
    @ApiOperation(value = "新增还书记录")
    @Log("还书保存")
    @PostMapping("/save")
    public R save(@RequestBody ReturnBooks returnBooks) {
        boorowBooksService.removeById(returnBooks.getBookId());
        returnBooks.setReturnTime(new Date());
        return new R(returnBooksService.save(returnBooks));
    }
}

